<?php

include 'postclass.php';
include 'connect.php';

$content = $_POST['content'];
$user = $_POST['user'];

$input = new input();

if(!$input->post($content)){
	die('留言的内容不正确');
}else if (!$input->post($user)) {
	# code...
	die('留言人不正确');
}




$time = time();
if(isset($_COOKIE['lasttime'])){
	$ctime = $time - $_COOKIE['lasttime'];
	if($ctime<60*0){
		$ctime = 60*5-$ctime;
		die("距离上次留言时间还有{$ctime}秒");
	}else{
		setcookie('lasttime',time());
	}
}else{
	setcookie('lasttime',time());
}


$sql = "INSERT INTO msg (content,user,time) VALUES ('{$content}','{$user}','{$time}')";
$result = $db->query($sql);
if(!$result){
	die('留言失败');
}else{
	header('location:index.php');
}
?>